package member.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1. 로그인 체크
		HttpSession session = request.getSession();
		//2. 처리
		//2-1 로그인 한 클라이언트의 경우 - 로그아웃 처리(Session 소멸)
		// /member/logout_success.jsp(안녕히가세요.)
		String url = null;
		if(loginCheck(session)){
			session.invalidate();
			url = "/member/logout_success.jsp";
		}else{
		//2-2.로그인 않나 클라이언트의 경우
		// /member/login_form.jsp
			url = "/member/login_form.jsp";
		}
		RequestDispatcher rdp = request.getRequestDispatcher(url);
		rdp.forward(request, response);
	}
	public boolean loginCheck(HttpSession session){
		Object o = session.getAttribute("login_member");
		if(o!=null){
			return true;
		}else{
			return false;
		}
	}

}
